package com.ec.base;

import com.ec.constants.Constants;

/**
 * Created by VincentZee on 2019/1/31
 */
public class BaseController {

    /**
     * 返回成功
     * @return
     */
    public ResponseBase setResultSuccess(){
        return setResult(Constants.HTTP_RES_CODE_200, Constants.HTTP_RES_CODE_200_VALUE, null);
    }

    /**
     * 返回成功，可附加data
     * @param data
     * @return
     */
    public ResponseBase setResultSuccess(Object data){
        return setResult(Constants.HTTP_RES_CODE_200, Constants.HTTP_RES_CODE_200_VALUE, data);
    }

    /**
     * 返回失败
     * @param msg
     * @return
     */
    public ResponseBase setResultError(String msg){
        return setResult(Constants.HTTP_RES_CODE_500, msg, null);
    }

    /**
     * 自定义返回结果
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public ResponseBase setResult(Integer code,String msg, Object data){
        return new ResponseBase(code, msg, (null == data)?null:data);
    }
}
